/*
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

#ifndef _BAKALARKA_H
#define _BAKALARKA_H

#include <QMainWindow>
#include <QAction>
#include <QMenu>
#include <QMdiArea>
#include <QSignalMapper>
#include <QMenuBar>
#include <QMdiSubWindow>
#include <QFileDialog>
#include <QStatusBar>
#include <QPointF>
#include <QPoint>
#include <QTreeView>
#include <QDockWidget>
#include <QToolBar>
#include <QSettings>
#include <QByteArray>
#include <QCloseEvent>
#include <QIcon>
#include <QDesktopServices>
#include <QMatrix>
#include <QRect>
#include <QMessageBox>
#include <QLibraryInfo>
#include <QStringList>
#include <QCoreApplication>
#include <QDir>

#include "mdiWindow.h"
#include "gObjects.h"
#include "statusWidget.h"
#include "drawArea.h"
#include "gObjects.h"
#include "tools.h"
#include "recentlyOpened.h"
#include "dialogs.h"
#include "assistant.h"
#include "dialogs.h"

#define TRANSLATE_TOOL	0
#define ROTATE_TOOL		1
#define TOO_TOOl		2

#define SETTINGS_COMPANY		"Glass Abrasiv s.r.o"
#define SETTINGS_PRODUCT		"LegoPlot"
#define SETTINGS_DEFAULT_SIZE	QSize(640, 480)).toSize()
#define SETTINGS_DEFAULT_POS	QPoint(0, 0)).toPoint()
#define SETTINGS_NAME_SIZE		"size"
#define SETTINGS_NAME_POS		"pos"
#define SETTINGS_NAME_AREA		"area"
#define SETTINGS_NAME_FILE		"file"
#define SETTINGS_HISTORY		"history"
#define DOC_MANUAL_URL			"/home/jena/c++/bakalarka/doc/www/manual.htm"

class mdiWindow;
class gObjects;
class translateTool;
class rotateTool;
class toolTool;
class morphTool;

class windowHistory{
	
	private:
		QMatrix matrix;
		Qt::WindowStates state;
		QRect rect;
		QString path;
		QPoint point;
	
	public:
		windowHistory();
		
		void setHistory(mdiWindow &window);
		void memberWindow(mdiWindow &window);
		void writeSettings(QSettings &);
		void readSettings(QSettings &);

};

class bakalarka: public QMainWindow{

	Q_OBJECT

	private:
		QAction *open;
		QAction *save;
		QAction *saveAs;
		QAction *quit;
		
		QAction *toolOpen;
		QAction *toolSave;
		QAction *toolSaveAs;
		QAction *toolZoomIn;
		QAction *toolZoomOut;
		QAction *toolZoomFit;
		QAction *toolZoomOriginal;
		
		QAction *showObjects;
		QAction *showTranslate;
		QAction *showRotate;
		QAction *showTool;
		QAction *showMorph;
		
		QAction *preview3d;
		QAction *edit;
		
		QAction *help;
		QAction *home;
		
		QMenu *file, *showMenu, *toolMenu, *about;
		QMenu *scale;
		QToolBar *fileToolBar, *scaleToolBar;
		QMdiArea *mdiArea;
		gObjects *view;
		translateTool *translate;
		rotateTool *rotate;
		toolTool *tool;
		morphTool *morph;
		statusWidget *status;
		recentlyOpened *openedFiles;
		QSignalMapper *windowMapper;
		bool fileProcess;
		QMdiSubWindow *lastActivateWindow;
		assistant helpAssistant;
		windowHistory history;
        bool once;
		
		void createActions();
		void createMenus();
		void createToolBars();
		void createStatusBar();
		void createObjects();
		void createToolBar();
		void createTranslate();
		void createRotate();
		void createTool();
		void createMorph();
		void readSettings();
		void writeSettings();
		QMdiSubWindow *findMdiWindow(const QString &);
	
    signals:
        void openFileByArg(QString);

	private slots:
        void activateWindow(QMdiSubWindow *);
		void openSlot();
		void saveSlot();
		void saveAsSlot();
		void showCoordinates(QPointF *);
		void showObject(gObject *);
		void zoomIn();
		void zoomOut();
		void zoomFit();
		void zoomOriginal();
		void setScale();
		void areaClicked(gTypeGo *, const QPointF &);
		void quickOpen(QAction *);
		void openEdit();
		void openPreview3d();
		void openAbout();
        void changeModel(containerModel *);
	
	public slots:
		void closeSubWindow(const QString &);
		void reloadSubWindow(QMdiSubWindow *);
		void closeSubWindow(QMdiSubWindow *);
		void setActiveSubWindow(QWidget *);
        void newMdiWindow(QString);
		void openManual();
		void saveWindowHistory(mdiWindow &);
	
	protected:
		virtual void closeEvent(QCloseEvent *);
        virtual void paintEvent(QPaintEvent *);
	
	public:
		bakalarka();
		
		drawArea *getDrawArea() const;
		mdiWindow *activeMdiWindow() const;
		assistant *getAssistant();

};

#endif
